<?php

namespace app\stationpc\controller;

/**
 * 用户相关类
 * Class Common
 * @package app\user\controller
 */
class Member extends Common
{
    protected $station_id;

    public function _initialize()
    {
        parent::_initialize();
        $obj = new \app\logic\Passport($this->str_module_name);
        $this->station_id = $obj->_checkPassport($this->_getContentParams('passport'), $this->_getParams('platform'));
        unset($obj);
    }

    /**
     * IP查找地址
     * @param string $ip
     * @return bool|mixed|string
     */
    public function GetIpLookup($ip = '')
    {
        if (empty($ip)) {
            return '请输入IP地址';
        }
        $res = @file_get_contents('http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=' . $ip);
        if (empty($res)) {
            return false;
        }
        $jsonMatches = array();
        preg_match('#\{.+?\}#', $res, $jsonMatches);
        if (!isset($jsonMatches[0])) {
            return false;
        }
        $json = json_decode($jsonMatches[0], true);
        if (isset($json['ret']) && $json['ret'] == 1) {
            $json['ip'] = $ip;
            unset($json['ret']);
        } else {
            return false;
        }
        return $json;
    }

    /**
     * 判断是否倒序
     * @param string $str_key
     * @param $str_order
     * @return string
     */
    public function listOrder($str_key = "gmt_create", $str_order)
    {
        if ($str_order == 'desc') {
            $str_order = $str_key . " desc";
        } else {
            $str_order = $str_key;
        }
        return $str_order;
    }

    /**
     * 拼接站点地址的json
     * @param $arr_data
     * @return string
     */
    public function packingListDetailsAddress($arr_data){
        $arr_data = json_decode($arr_data);
        return $arr_data->prov_name."".$arr_data->city_name."".$arr_data->county_name."".$arr_data->street_name."".$arr_data->detail_address;
    }
}
